package com.utry.netty.client;


import com.utry.netty.bean.PkgDataBean;
import com.utry.netty.util.JsonUitl;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class JsonEncoder extends MessageToByteEncoder<PkgDataBean> {

    @Override
    protected void encode(ChannelHandlerContext ctx, PkgDataBean user, ByteBuf buf)
            throws Exception {
        String json = JsonUitl.objectToString(user);
        ByteBuf byteBuf = Unpooled.wrappedBuffer(json.getBytes());
        ctx.writeAndFlush(byteBuf);
    }

}
